﻿#include "System.h"
#include "Application.h"
#include "Mesh.h"
System::System(const Configuration& cfg)
  : Object(cfg)
  , _app(*(Get<Application*>("_app")))
  , _mesh(*(_app.GetMesh()))
{
}

void System::Init()
{
  _timer.Start();
  _mesh.Build();
  Info("Build网格完成，运行时间: ", _timer.GetElapsedTime());

  if (!_mesh.IsPrepared())
  {
    Error("Mesh没有准备好.");
  }

  //_mesh.BuildFaceTopo(_bnd_name_id);
  //Info("BuildFaceTopo网格完成，运行时间: ", _timer.GetElapsedTime());
}

void System::AddBoundaryCondition(const std::pair<std::string, std::vector<std::string>>& bc_pair)
{

  auto valid_bc_type = [&]() -> std::string
  {
    std::stringstream ss;
    ss << "[";
    for (auto& var : _bnd_type_id)
    {
      ss << var.first << ",";
    }
    ss << "]";
    return ss.str();
  };

  auto type = bc_pair.first;
  for (auto& boundary_name : bc_pair.second)
  {
    try
    {
      auto bid = _bnd_type_id.at(type);
    }
    catch (const std::exception&)
    {
      Error("未定义BC类型:", type, ".可用BC类型:", valid_bc_type());
    }
    _bnd_name_id.insert({ boundary_name, _bnd_type_id[type] });
  }
}
